!
!
!
      subroutine PLUTOXYZ (tjd,lu,r,ierr)
!-----------------------------------------------------------------------
!
!     Ref : 9902.
!
!     Pluto : heliocentric rectangular coordinates (Ecliptic J2000).
!
! --- Input ------------------------------------------------------------
!
!     tjd    Julian Date (double precision).
!
!     lu     Logical unit for the file plutoxyz.dat (integer).
!
! --- Output -----------------------------------------------------------
!
!     r(3)   Rectangular coordinates (X,Y,Z) in astronomical unit 
!            (double precision).
!
!     ierr   Error index (integer).
!            0 : no error.
!            1 : time error.
!            2 : file error.
!
! --- Remark -----------------------------------------------------------
!
!     The file plutoxyz.dat (logical unit lu) is opened in Main program.
!
!     The Julian Date tjd is included between 626403.5 (-2997 Jan 1) and
!     2810943.5 (2984 Jan 1)
!
! --- Declarations -----------------------------------------------------
!
      implicit double precision (a-h,o-z)
      logical first
!
      dimension r(3),x(0:2),nt(3,0:2)
      dimension a0(3),a1(3),ampli(662),fnu(662),phi(662)
!
      save
!
! --- Initialization ---------------------------------------------------
!
      parameter (dgrad=0.1745329251994330d-1)
      parameter (tmin=626403.5d0,tmax=2810943.5d0)
!
      data first/.true./
!
! --- Date test --------------------------------------------------------
!
      if (tjd.lt.tmin.or.tjd.gt.tmax) then
         ierr=1
         return
      endif
!
! --- Reading Pluto series ---------------------------------------------
!
      if (first) then
         m=0
         read (lu,1001,err=100,end=100)
         do iv=1,3
            read (lu,1002,err=100) a0(iv),a1(iv)
            do k=0,2
               read (lu,1003,err=100) nt(iv,k)
               do n=1,nt(iv,k)
                  m=m+1
                  read (lu,1004,err=100) ampli(m),fnu(m),phi(m)
               enddo
            enddo
         enddo
         first=.false.
      endif
!
! --- Time variables ---------------------------------------------------
!
      t=(tjd-2451545.d0)/365.25d0
!
      x(0)=1.d0
      x(1)=2.d0*(tjd-626150.5d0)/2185000.d0-1.d0
      x(2)=x(1)*x(1)
!
! --- Time substitution ------------------------------------------------
!
      m=0
      do iv=1,3
         r(iv)=0.d0
         do k=0,2
            do n=1,nt(iv,k)
               m=m+1
               arg=fnu(m)*t+phi(m)*dgrad
               r(iv)=r(iv)+ampli(m)*x(k)*sin(arg)
            enddo
         enddo
         r(iv)=r(iv)+a0(iv)+a1(iv)*x(1)
      enddo
!
      ierr=0
      return
!
! --- File error -------------------------------------------------------
!
100   continue
!
      ierr=2
      return
!
! --- Formats ----------------------------------------------------------
!
1001  format (10(/))
1002  format (////2f13.6)
1003  format (/31x,i3//)
1004  format (f15.8,f15.10,f12.5)
!
      end
!
!
!
